package com.repository;

import com.entity.Menu;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;

/**
 * @author Yadasu
 * @date 2020/12/22 9:18
 */

public interface MenuRepository extends JpaRepository<Menu,Integer> {


    @Query(value = "select * from sys_menu where  pid=?1",nativeQuery = true)
    List<Menu>findParentByPid(Integer pid);

    @Query(value = "select * from sys_menu where  pid=?1 and id=?2",nativeQuery = true)
    List<Menu>findParentByPidAndId(Integer pid,Integer id);


    /**
     * 根据角色ID与菜单类型查询菜单
     * @param roleIds roleIDs
     * @param type 类型
     * @return /
     */
    @Query(value = "SELECT m.* FROM sys_menu m, sys_roles_menus r WHERE " +
            "m.id = r.menu_id AND r.role_id IN ?1 AND type != ?2 ",nativeQuery = true)
    LinkedHashSet<Menu> findByRoleIdsAndTypeNot(Set<Long> roleIds, int type);
}
